package main

import (
	"net"
)

type User struct {
	name       string
	addr       string
	connection net.Conn
	msgChannel chan string
}

func newUser(name, addr string, connection net.Conn, msgChannel chan string) (user *User) {
	user = &User{
		name:       name,
		addr:       addr,
		connection: connection,
		msgChannel: msgChannel,
	}
	go user.waitMsgFromChannel()
	return user
}

func (user *User) waitMsgFromChannel() {
	for {
		message := <-user.msgChannel
		msgFromServer := []byte(message)
		_, err := user.connection.Write(msgFromServer)
		if err != nil {
			return
		}
	}

}
